package com.empsys.mapper;

import com.empsys.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author wzm
 * @create 2023-12-08 10:34
 * project_name:web2310
 * @Description
 */
@Mapper
public interface EmpMapper {
    /*原生分页*/
    /**
     * 分页查询
     * @param begin 索引
     * @param pageSize 条数
     * @return 查询数据的集合
     */
    @Select("select * from emp limit #{begin},#{pageSize}")
    List<Emp> listByPage(Integer begin, Integer pageSize);

    //查询总记录数
    @Select("select count(1) from emp")
    Long count();

    /*pagehelper不带条件*/
   /* @Select("select * from emp")
    List<Emp> list();*/


    //带条件分页
    List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    void delete(List<Integer> ids);

    @Insert("insert into emp(username,name,gender,image,job,entrydate,dept_id,create_time,update_time)" +
            " values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where id = #{id}")
    Emp selectById(Integer id);

    void updateById(Emp emp);

    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from emp where username = #{username} and password = #{password}")
    Emp getByUseNameAndPassWord(Emp emp);

    //根据部门id删除这个部门的所有员工
    @Delete("delete from emp where dept_id = #{id}")
    void deleteByDeptId(Integer id);
}
